#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>

/** Autuor : zhaoshun
  * Time   : 2017/12/03 19:120
  * Email  : tmby1314@163.com
  * student ID: 716101010107
  * */

int main_fread_fwrite(int argc, char const *argv[]) {

    if (NULL == argv[1] || NULL == argv[2]) {
        printf("Usage : copy file1 file1");
        exit(10);
    }

    const size_t nitems = 1;
    const size_t size = 1;
    char buff[nitems];
    FILE *in, *out;
    char *tmp;
    char const *src_file = argv[1];
    char const *dest_file = argv[2];
    if (NULL == argv[1] || NULL == argv[2]) {
        printf("Usage : copy file1 file1");
        exit(10);
    }

    size_t read_size, write_size;
    in = fopen(src_file, "r+");
    out = fopen(dest_file, "w+");

    while ((read_size = fread(buff, size, nitems , in)) > 0) {
        tmp = buff;
        while (read_size) {
            write_size = fwrite(buff, size, read_size , out);
            read_size = read_size - write_size;
            tmp += write_size;
        }

    }
    return 0;
}